package com.ruoyi.web.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.web.business.domain.MfuResource;
import com.ruoyi.web.business.service.IMfuResourceService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 资源管理Controller
 * 
 * @author ruoyi
 * @date 2022-05-07
 */
@RestController
@RequestMapping("/resource")
public class MfuResourceController extends BaseController
{
    @Autowired
    private IMfuResourceService mfuResourceService;

    /**
     * 查询资源管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:resource:list')")
    @GetMapping("/list")
    public AjaxResult list(MfuResource mfuResource)
    {
        List<MfuResource> list = mfuResourceService.selectMfuResourceList(mfuResource);
        return AjaxResult.success(list);
    }

    @PreAuthorize("@ss.hasPermi('system:resource:list')")
    @GetMapping("/buildTreeList")
    public AjaxResult buildTreeList(MfuResource mfuResource)
    {
        List<MfuResource> list = mfuResourceService.selectMfuResourceList(mfuResource);
        List<MfuResource> resList = mfuResourceService.buildTreeList(list);
        return AjaxResult.success(resList);
    }

    /**
     * 导出资源管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:resource:export')")
    @Log(title = "资源管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MfuResource mfuResource)
    {
        List<MfuResource> list = mfuResourceService.selectMfuResourceList(mfuResource);
        ExcelUtil<MfuResource> util = new ExcelUtil<MfuResource>(MfuResource.class);
        util.exportExcel(response, list, "资源管理数据");
    }

    /**
     * 获取资源管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:resource:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(mfuResourceService.selectMfuResourceById(id));
    }

    /**
     * 新增资源管理
     */
    @PreAuthorize("@ss.hasPermi('system:resource:add')")
    @Log(title = "资源管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MfuResource mfuResource)
    {
        return toAjax(mfuResourceService.insertMfuResource(mfuResource));
    }

    /**
     * 修改资源管理
     */
    @PreAuthorize("@ss.hasPermi('system:resource:edit')")
    @Log(title = "资源管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MfuResource mfuResource)
    {
        return toAjax(mfuResourceService.updateMfuResource(mfuResource));
    }

    /**
     * 删除资源管理
     */
    @PreAuthorize("@ss.hasPermi('system:resource:remove')")
    @Log(title = "资源管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mfuResourceService.deleteMfuResourceByIds(ids));
    }
}
